var basePath = getBasePath();
//录入条目的数量
var testProdInfoItemCount=0;
//1.查询所有的录入条目
function getAllTestProdInfoItem(labcode) {
    $.ajax({
        type: "get",
        url: basePath+config.bxxs.apiPath+"/TestProdInfoItem/getAllTestProdInfoItem",
        data:{
            labcode:labcode
        },
        success: function (msg) {
            testProdInfoItemCount=msg.length;
            var item = "<thead>" + "<tr class='alert alert-success alert-dismissable'>" +
                "<td><strong>台位名称</strong></td>"+
                "<td><strong>是否在测</strong></td>"+
                "<td><strong>开测时间</strong></td>"+
                "<td><strong>停测时间</strong></td>";
            $("#table_content tr").eq(1).remove();
            for (var i = 0; i < msg.length; i++) {
                //拼接字符串
                item = item + "<td><strong>" + (msg[i].itemname) + "</strong></td>";
            }
            item = item + "</tr>" + "</thead>";
            $("#table_content").append(item);
        },
        error: function (e) {
            alert("网页发生错误：", e, "error");
        }
    });
}

//2.获取所有的测试元数据
function getAllTestProdInfoValue(labcode,pageNum) {
    let layerid=layer.msg('加载中', {
        icon: 16,
        shade: 0.4,
        time:false //取消自动关闭
    });
    $.ajax({
        type: "get",
        url: basePath+config.bxxs.apiPath+"/TestProdInfoValue/getAllTestProdInfoValue",
        data:{
            labcode:labcode,
            pageNum:pageNum
        },
        success: function (msg) {
            layer.close(layerid);//手动关闭
            var item = "<tbody>";
            $("#table_content tbody tr").remove();
            for (var i = 0; i < msg.list.length; i++) {
                //判断是否开测
                let testnow=(msg.list[i].testnow=="0"?"否":"是");
                //根据台位编码获取台位名称
                let unitName=getUnitNameByUnitNo(msg.list[i].testunitno);
                if (i % 2) {
                    //拼接字符串
                    item = item + "<tr class='info'>" +
                        "<td>" + unitName+ "</td>" +
                        "<td>" + testnow + "</td>" +
                        "<td>" + msg.list[i].begindatetime + "</td>" +
                        "<td>" + msg.list[i].enddatetime + "</td>";
                    for (var j = 1; j <= testProdInfoItemCount; j++){
                        let itemcontent="msg.list[i].itemcontent"+j;
                        item = item + "<td>" +eval(itemcontent)+"</td>";
                    }
                    item = item + "</tr>";
                }
                else {
                    //拼接字符串
                    item = item + "<tr>" +
                        "<td>" + unitName + "</td>" +
                        "<td>" + testnow + "</td>" +
                        "<td>" + msg.list[i].begindatetime + "</td>" +
                        "<td>" + msg.list[i].enddatetime + "</td>";
                    for (var j = 1; j <= testProdInfoItemCount; j++){
                        let itemcontent="msg.list[i].itemcontent"+j;
                        item = item + "<td>" +eval(itemcontent)+"</td>";
                    }
                    item = item + "</tr>";
                }

            }
            item = item + "</tbody>";
            $("#table_content").append(item);
            var pageNum = msg.pageNum;
            var total = msg.total;
            var pages= msg.pages;
            //设置页码
            $("#total").text(total);
            $("#pageNum").text(pageNum);
            $("#pages").text(pages);
        },
        error: function (e) {
            alert("网页发生错误：", e, "error");
        }
    });
}